#ifndef TESTGAME_NETWORK_MANAGER_H
#define TESTGAME_NETWORK_MANAGER_H

#include <string>

#include "cocos2d.h"
#include "network/WebSocket.h"

class NetworkManager : public cocos2d::network::WebSocket::Delegate {
public:
    static NetworkManager *getInstance();
    bool init();
    bool connect(const std::string &url);
    void disconnect();

    virtual void onOpen(cocos2d::network::WebSocket* ws) override;
    virtual void onMessage(cocos2d::network::WebSocket* ws,
        const cocos2d::network::WebSocket::Data& data) override;
    virtual void onClose(cocos2d::network::WebSocket* ws) override;
    virtual void onError(cocos2d::network::WebSocket* ws,
        const cocos2d::network::WebSocket::ErrorCode& error) override;

private:
    CC_DISALLOW_COPY_AND_ASSIGN(NetworkManager);

    NetworkManager();
    virtual ~NetworkManager();

    cocos2d::network::WebSocket* socket_;
};

#endif

